/**
 * @file filter
 * @author liaoxuezhi@baidu.com
 */
/* eslint fecs-indent: [0, "space", 2, 2] */

import * as React from 'react';
import {
  PureComponent,
  PropTypes
} from 'react';

import {Renderer} from '../../renderer';

@Renderer({
  name: 'field-plain',
  desc: '...',
  test: /(?:^|\/)field\/(?:plain|text)$/
})
export default class PlainField extends PureComponent {
  static propTypes = {
    className: PropTypes.string,
    type: PropTypes.string.isRequired,
    placeholder: PropTypes.string,
    innerClassName: PropTypes.string
  };

  static defaultProps = {
    placeholder: '-',
    innerClassName: ''
  };

  render() {
    const {
      value,
      placeholder,
      className
    } = this.props;

    let body = value || value === 0 ? String(value)
      : (placeholder && (<span className="text-muted">{placeholder}</span>));

    return (
      <span className={className}>
        {body}
      </span>
    );
  }
}
